package com.example.hangzhou.welbeing.mytestdemoapp.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.transition.Slide;
import android.transition.TransitionManager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.hangzhou.welbeing.mytestdemoapp.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 杭州惟君医疗科技有限公司10
 * Created by 20433 on 2018/5/9
 *
 * @desc 东风山河绿，春已不折柳，繁花看不尽，处处惹人留
 * @desc 佛祖镇楼，bug辟容易
 */

public class SlideFragment extends Fragment {
    @Bind(R.id.fragment_transition_note_slide_button1)
    Button fragmentTransitionNoteSlideButton1;
    @Bind(R.id.fragment_transition_note_slide_tv_01)
    TextView fragmentTransitionNoteSlideTv01;
    @Bind(R.id.fragment_transition_note_slide_tv_02)
    TextView fragmentTransitionNoteSlideTv02;
    @Bind(R.id.fragment_transition_note_slide_tv_03)
    TextView fragmentTransitionNoteSlideTv03;
    @Bind(R.id.fragment_transition_note_slide_tv_04)
    TextView fragmentTransitionNoteSlideTv04;
    @Bind(R.id.fragment_transition_note_slide_rl)
    RelativeLayout fragmentTransitionNoteSlideRl;
    @Bind(R.id.fragment_transition_note_slide_ll)
    LinearLayout fragmentTransitionNoteSlideLl;
    private Context mcontext;
    private List<View> mViews = new ArrayList<>();
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mcontext = context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = View.inflate(mcontext, R.layout.fragment_transition_note_slide, null);
        ButterKnife.bind(this, view);
        mViews.add(fragmentTransitionNoteSlideTv01);
        mViews.add(fragmentTransitionNoteSlideTv02);
        mViews.add(fragmentTransitionNoteSlideTv03);
        mViews.add(fragmentTransitionNoteSlideTv04);
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick(R.id.fragment_transition_note_slide_button1)
    public void onViewClicked() {
        //向右滑出
        Slide slide = new Slide(Gravity.RIGHT);
//设置滑动的时间
        slide.setDuration(1000);

        TransitionManager.beginDelayedTransition(fragmentTransitionNoteSlideRl, slide);
        int vis = mViews.get(0).getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE;
        for (View view : mViews) {
            view.setVisibility(vis);
        }
    }
}
